<?php
/**
 * @version        $Id: reg_new.php 1 8:38 2010年7月9日Z tianya $
 * @package        DedeCMS.Member
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
require_once(dirname(__FILE__)."/config.php");
require_once DEDEINC.'/membermodel.cls.php';
if($cfg_mb_allowreg=='N')
{
    ShowMsg('系统关闭了新用户注册！', 'index.php');
    exit();
}

if(!isset($dopost)) $dopost = '';

/* if(!$cfg_ml->IsLogin())
{
	ShowMsg("尚未完成基本信息的注册,请返回重新填写！", "index_do.php?fmdo=user&dopost=regnew");
	exit;
} else {
	if($cfg_ml->fields['spacesta'] == 2)
	{
		 ShowMsg('你已经登陆系统，无需重新注册！', 'index.php');
		 exit;
	}
} */
$membermodel = new membermodel($cfg_ml->M_MbType);
$postform = $membermodel->getForm(true);

if($dopost == 'reginfo')
{	

	//这里完成详细内容填写
	$dede_fields = empty($dede_fields) ? '' : trim($dede_fields);
	$dede_fieldshash = empty($dede_fieldshash) ? '' : trim($dede_fieldshash);
	$modid = empty($modid)? 0 : intval(preg_replace("/[^\d]/",'', $modid));
	
	if(!empty($dede_fields))
	{
		if($dede_fieldshash != md5($dede_fields.$cfg_cookie_encode))
		{
			showMsg('数据校验不对，程序返回', '-1');
			exit();
		}
	}
	$modelform = $dsql->GetOne("SELECT * FROM #@__member_model WHERE id='$modid' ");
	if(!is_array($modelform))
	{
		showmsg('模型表单不存在', '-1');
		exit();
	}
	$inadd_f = '';
	if(!empty($dede_fields))
	{
		$fieldarr = explode(';', $dede_fields);
		if(is_array($fieldarr))
		{
			foreach($fieldarr as $field)
			{
				if($field == '') continue;
				$fieldinfo = explode(',', $field);
				if($fieldinfo[1] == 'textdata')
				{
					${$fieldinfo[0]} = FilterSearch(stripslashes(${$fieldinfo[0]}));
					${$fieldinfo[0]} = addslashes(${$fieldinfo[0]});
				}
				else
				{
					if(empty(${$fieldinfo[0]})) ${$fieldinfo[0]} = '';
					${$fieldinfo[0]} = GetFieldValue(${$fieldinfo[0]}, $fieldinfo[1],0,'add','','diy', $fieldinfo[0]);
				}
				if($fieldinfo[0]=="birthday") ${$fieldinfo[0]}=GetDateMk(${$fieldinfo[0]});
				$inadd_f .= ','.$fieldinfo[0]." ='".${$fieldinfo[0]}."' ";
			}
		}

	}
	

	$query = "UPDATE `{$membermodel->table}` SET `mid`='{$cfg_ml->M_ID}' $inadd_f WHERE `mid`='{$cfg_ml->M_ID}'; ";
	if($dsql->executenonequery($query))
	{
		$dsql->ExecuteNoneQuery("UPDATE `#@__member` SET `spacesta`='2' WHERE `mid`='{$cfg_ml->M_ID}'");
		// 清除缓存
		$cfg_ml->DelCache($cfg_ml->M_ID);
		require_once(DEDEMEMBER."/tpl/reg_page3.htm");
		exit;
	}






require_once(DEDEMEMBER."/tpl/reg_page2.htm");
	
/* 	if($dopost == 'reginfo')
    {
		
		$dsql->ExecuteNoneQuery("UPDATE `#@__member_player` SET 
						fullname = '{$_POST['']}'
						
						WHERE `mid`='{$cfg_ml->M_ID}';");
		
  
        $query = "UPDATE `{$membermodel->table}` SET `mid`='{$cfg_ml->M_ID}' $inadd_f WHERE `mid`='{$cfg_ml->M_ID}'; ";
        if($dsql->executenonequery($query))
        {
            $dsql->ExecuteNoneQuery("UPDATE `#@__member` SET `spacesta`='2' WHERE `mid`='{$cfg_ml->M_ID}'");
            // 清除缓存
            $cfg_ml->DelCache($cfg_ml->M_ID);
            require_once(DEDEMEMBER."/templets/reg-new3.htm");
            exit;
        }
    } */
	
    
}